package com.easyhouse.common.utils;

import com.easyhouse.common.pojo.Product;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.lang.StringUtils;

public class StringConversionJavabeanUtils {
    public static Product StringJava(String productString){
        Product product = new Product();
        String houseId = StringUtils.substringBetween(productString, "houseId=", ",");
        String houseName = StringUtils.substringBetween(productString, "houseName=", ",");
        String houseType = StringUtils.substringBetween(productString, "houseType=", ",");
        String houseArea = StringUtils.substringBetween(productString, " houseArea=", ",");
        if (houseArea!=null& !houseArea.trim().equals("") & !houseArea.trim().equals("null")) {
            double houseArea1 = Double.parseDouble(houseArea);
            product.setHouseArea(houseArea1);
        }
        String productPrice = StringUtils.substringBetween(productString, "productPrice=", ",");
        if (productPrice!=null& !productPrice.trim().equals("") & !productPrice.trim().equals("null")) {
            double productPrice1 = Double.parseDouble(productPrice);
            product.setProductPrice(productPrice1);
        }
        String houseAddr = StringUtils.substringBetween(productString, "houseAddr=", ",");
        String addrProvince = StringUtils.substringBetween(productString, "addrProvince=", ",");
        String addrDistrict = StringUtils.substringBetween(productString, " addrDistrict=", ",");
        String imgUrl = StringUtils.substringBetween(productString, "imgUrl=", ",");
        String sellStatus = StringUtils.substringBetween(productString, "sellStatus=", ",");
        if (sellStatus!=null& !sellStatus.trim().equals("") & !sellStatus.trim().equals("null")) {
            Integer sellStatus1 = Integer.parseInt(sellStatus);
            product.setSellStatus(sellStatus1);
        }
        String userId = StringUtils.substringBetween(productString, "userId=", ",");
        String consumerId = StringUtils.substringBetween(productString, "consumerId=", ",");
        String houseDescription = StringUtils.substringBetween(productString, "houseDescription=", ",");
        String extend = StringUtils.substringBetween(productString, "extend=", ",");

        if (houseId!=null) {
            product.setHouseId(houseId);
        }
        if (houseId!=null) {
            product.setHouseName(houseName);
        }
        if (houseType!=null) {
            product.setHouseType(houseType);
        }
        if (houseAddr!=null) {
            product.setHouseAddr(houseAddr);
        }
        if (addrProvince!=null) {
            product.setAddrProvince(addrProvince);
        }
        if (addrDistrict!=null) {
            product.setAddrDistrict(addrDistrict);
        }
        if (imgUrl!=null) {
            product.setImgUrl(imgUrl);
        }
        if (userId!=null) {
            product.setUserId(userId);
        }
        if (consumerId!=null) {
            product.setConsumerId(consumerId);
        }
        if (houseDescription!=null) {
            product.setHouseDescription(houseDescription);
        }
        if (extend!=null) {
            product.setExtend(extend);
        }

        return product;
    }
}
